import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
Vue.use(Router)
// import tableRouter from './modules/table'
/* Router Modules */
export const constantRoutes = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true,
		meta: {
			title: '登录',
			permissions: ['admin', 'sponsor']
		}
  },
	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index'),
			name: 'Dashboard',
			meta: {
				title: '首页',
				icon: 'dashboard',
				noCache: true,
				affix: true,
				permissions: ['admin', 'sponsor']
			}
    }]
  },
	{
		path: '/user-manage',
		component: Layout,
		redirect: '/user-manage/index',
		meta: { title: '用户管理', icon: 'el-icon-user' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/user-manage/index'),
				name: 'UserManage',
				meta: { title: '用户管理', icon: 'el-icon-user', permissions: ['admin'] }
	    },
			{
				path: 'detail',
				component: () => import('@/views/user-manage/detail'),
				name: 'UserManageDetail',
				meta: {
					title: '用户详情',
					icon: 'el-icon-user',
					permissions: ['admin'],
					activeMenu: '/user-manage/index'
				},
				hidden: true
			}
	  ]
  }, {
		path: '/competition-manage',
		component: Layout,
		redirect: '/competition-manage/index',
		meta: { title: '赛事管理', icon: 'el-icon-trophy' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/competition-manage/index'),
				name: 'CompetitionManage',
				meta: {
					title: '赛事管理',
					icon: 'el-icon-trophy',
					permissions: ['admin']
				}
	    },
			{
				path: 'create',
				component: () => import('@/views/competition-manage/create'),
				name: 'CreateCompetition',
				meta: {
					title: '创建赛事',
					permissions: ['admin'],
					activeMenu: '/competition-manage/index'
				},
				hidden: true
			},
			{
				path: 'detail',
				component: () => import('@/views/competition-manage/detail'),
				name: 'CompetitionDetail',
				meta: {
					title: '赛事详情',
					permissions: ['admin'],
					activeMenu: '/competition-manage/index'
				},
				hidden: true
			},
			{
				path: 'certificate',
				component: () => import('@/views/competition-manage/certificate'),
				name: 'CompetitionCertificate',
				meta: {
					title: '赛事证书',
					permissions: ['admin'],
					activeMenu: '/competition-manage/index'
				},
				hidden: true
			},
			{
				path: 'editSign',
				component: () => import('@/views/competition-manage/editSign'),
				name: 'CompetitionEditSign',
				meta: {
					title: '修改选手参赛信息',
					permissions: ['admin'],
					activeMenu: '/competition-manage/index'
				},
				hidden: true
			}
	  ]
  },
	{
		path: '/questions',
		component: Layout,
		redirect: '/questions/index',
		meta: { title: '题库管理', icon: 'el-icon-printer' },
		children: [
			{
				path: 'index',
				component: () => import('@/views/question-manage/index'),
				name: 'QuestionManage',
				meta: {
					title: '题库管理',
					icon: 'el-icon-printer',
					permissions: ['admin']
				}
	    },
			{
				path: 'create',
				component: () => import('@/views/question-manage/create'),
				name: 'CreateQuestion',
				meta: {
					title: '创建题库',
					permissions: ['admin'],
					activeMenu: '/questions/index'
				},
				hidden: true
			}
	  ]
	},
	{
		path: '/refund',
		component: Layout,
		children: [{
			path: 'index',
			component: () => import('@/views/refund-manage/index'),
			name: 'OrdersRefundList',
			meta: {
				title: '退费审核',
				icon: 'el-icon-document-checked',
				permissions: ['admin', 'sponsor']
			}
	  }]
	},
	{
		path: '/order',
		component: Layout,
		children: [{
			path: 'index',
			component: () => import('@/views/order-manage/index'),
			name: 'OrdersList',
			meta: {
				title: '订单管理',
				icon: 'el-icon-s-order',
				permissions: ['admin', 'sponsor']
			}
	  }]
	},
	// {
	// 	path: '/city',
	// 	component: Layout,
	// 	children: [{
	// 		path: '/city/index',
	// 		component: () => import('@/views/city-manage'),
	// 		name: 'CityManage',
	// 		meta: {
	// 			title: '城市管理',
	// 			icon: 'el-icon-office-building',
	// 			permissions: ['admin']
	// 		}
 //    }]
 //  }, 
	{
		path: '/lunbo',
		component: Layout,
		redirect: '/lunbo/index',
		meta: { title: '广告位管理', icon: 'el-icon-monitor' },
		children: [{
			path: 'index',
			component: () => import('@/views/lunbo-manage'),
			name: 'LunboManage',
			meta: {
				title: '广告位管理',
				icon: 'el-icon-monitor',
				permissions: ['admin']
			}
    }, {
			path: 'create',
			component: () => import('@/views/lunbo-manage/create'),
			name: 'LunboCreate',
			meta: {
				title: '新增广告',
				permissions: ['admin'],
				activeMenu: '/lunbo/index'
			},
			hidden: true
			}]
  },
	{
		path: '/news',
		component: Layout,
		meta: { title: '新闻管理', icon: 'el-icon-document' },
		children: [{
				path: '',
				component: () => import('@/views/news-manage/index'),
				name: 'ArticleList',
				meta: {
					title: '新闻管理',
					icon: 'el-icon-document',
					permissions: ['admin']
				}
	  },
			{
				path: 'create',
				component: () => import('@/views/news-manage/create'),
				name: 'newsCreate',
				meta: {
					title: '新增新闻',
					permissions: ['admin'],
					activeMenu: '/news'
				},
				hidden: true
		}]
	},
	{
		path: '/sponsor',
		component: Layout,
		meta: { title: '赞助商管理' },
		redirect: '/sponsor/index',
		children: [{
			path: 'index',
			component: () => import('@/views/sponsor-manage/index'),
			name: 'SponsorManage',
			meta: {
				title: '赞助商管理',
				icon: 'el-icon-notebook-2',
				permissions: ['admin']
			}
	  }, {
			path: 'send',
			component: () => import('@/views/sponsor-manage/send-quota.vue'),
			name: 'SponsorManageSend',
			meta: {
				title: '赠送名额',
				permissions: ['admin'],
				activeMenu: '/sponsor/index'
			},
			hidden: true
	  }]
	},
	{
		path: '/message',
		component: Layout,
		children: [{
			path: '',
			component: () => import('@/views/send-message/index'),
			name: 'SendMessage',
			meta: {
				title: '消息推送模版',
				icon: 'el-icon-position',
				permissions: ['admin']
			}
	  }]
	},
	{
		path: '/sendHistory',
		component: Layout,
		children: [{
			path: '',
			component: () => import('@/views/send-message/history'),
			name: 'SendMessage',
			meta: {
				title: '短信发送记录',
				icon: 'el-icon-tickets',
				permissions: ['admin']
			}
	  }]
	},
	{
		path: '/config',
		component: Layout,
		children: [{
			path: 'index',
			component: () => import('@/views/system/config.vue'),
			name: 'SystemConfig',
			meta: {
				title: '系统设置',
				icon: 'el-icon-setting',
				permissions: ['admin']
			}
	  }]
	},
	// {
	// 	path: '/feedback',
	// 	component: Layout,
	// 	redirect: '/feedback/index',
	// 	children: [{
	// 		path: 'index',
	// 		component: () => import('@/views/feedback-manage/index'),
	// 		name: 'FeedbacksList',
	// 		meta: {
	// 			title: '反馈列表',
	// 			icon: 'el-icon-notebook-2',
	// 			permissions: ['admin']
	// 		}
	//   }]
 //  },

	{
		path: '/404',
		component: () => import('@/views/error-page/404'),
		hidden: true,
		meta: { title: '404' }
  },
	{
		path: '/401',
		component: () => import('@/views/error-page/401'),
		hidden: true,
		meta: { title: '401' }
  }
]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: 'permission',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'permissionList',
  //       component: () => import('@/views/permission/permissionList'),
  //       name: 'permissionList',
  //       meta: {  title: '权限列表', roles: ['admin'] }
  //     }
  //   ]
  // },

  /** when your routing map is too long, you can split it into small modules **/
  // tableRouter,

  // 404 page must be placed at the end !!!
	{
		path: '*',
		redirect: '/404',
		hidden: true
  }
]
const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})
const router = createRouter()
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}
export default router